package com.yumis.service.modules.shop.controller;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.Shop;
import com.yumis.service.model.pojo.ShopVipCard;
import com.yumis.service.model.pojo.User;
import com.yumis.service.modules.shop.service.ShopVipCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("shopVipCard")
public class ShopVipCardController {
    @Autowired
    private ShopVipCardService shopVipCardService;

    /**
     * 查询所有的会员卡
     * @param page
     * @param rows
     * @return
     */
    @GetMapping("queryShopVipCard")
    public ResponseEntity<Response> queryShopVipCard(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                              @RequestParam(value = "rows", defaultValue = "10") Integer rows){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,shopVipCardService.queryShopVipCard(page,rows)));
    }

    /**
     * 新建会员卡模板
     * @param shopVipCard
     * @return
     */
    @PostMapping("addShopVipCard")
    public ResponseEntity<Response> addShopVipCard(@Valid ShopVipCard shopVipCard){
        shopVipCardService.addShopVipCard(shopVipCard);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("deleteShopVipCardById")
    public ResponseEntity<Response> deleteShopVipCardById(@RequestParam("id") Long id){
        shopVipCardService.deleteShopVipCardById(id);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @PostMapping("queryShopVipCardById")
    public ResponseEntity<Response> queryShopVipCardById(@RequestParam("id") Long id){
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK,shopVipCardService.queryShopVipCardById(id)));
    }

    /**
     * 修改
     * @param shopVipCard
     * @return
     */
    @PostMapping("updateShopVipCard")
    public ResponseEntity<Response> updateShopVipCard(@Valid ShopVipCard shopVipCard){
        shopVipCardService.updateShopVipCard(shopVipCard);
        return ResponseEntity.ok().body(Response.buildResponse(HttpState.OK));
    }
}
